<template>
  <div class="collection">
    <div class="collection-item" v-for="(item,index) in collecList" :key="index">
      <img :src="item.img" class="item-img">
      <div class="item-content">
        <div class="item-content-left">
          <div class="item-content-title">
            {{item.name}}
          </div>
          <div class="item-content-position">
            {{item.position}}
          </div>
        </div>
        <div class="item-content-right">
          <el-button type="warning" round plain @click="deleteCollect(item.id)">取消收藏</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Collection",
  data() {
    return {
      collecList: [], //收藏列表
    }
  },
  created() {
    this.getCollectList()
  },
  methods: {
    // 获取收藏列表
    getCollectList() {
      this.$axios({
        method: 'POST',
        url: '/getCollection',
        data: {
          phone: '18533534786'
        }
      }).then(res=>{
        if (res.data.result == 1) {
          this.collecList = res.data.list
        }
      })
    },
    // 删除景点收藏
    deleteCollect(id) {
      let temp = confirm("是否确定取消收藏？")
      if(temp) {
        this.$axios({
          method: 'POST',
          url: '/deleteCollection',
          data: {
            phone: '18533534786',
            id: id
          }
        }).then(res=>{
          if (res.data.result == 1) {
            // 加取消成功提示框
            this.$message({
              message: '取消收藏成功',
              type: 'success'
            });
            this.getCollectList()
          }
        })
      }
    }
  }
}
</script>

<style scoped>
  .collection {
    /*min-height: 100vh;*/
    background: linear-gradient(to bottom, #2c3e50, #ffffff);
    background: -webkit-linear-gradient(to bottom, #2c3e50, #ffffff);
    background: -o-linear-gradient(to bottom, #2c3e50, #ffffff);
    background: -ms-linear-gradient(to bottom, #2c3e50, #ffffff);
    background: -moz-linear-gradient(to bottom, #2c3e50, #ffffff);
    padding: 5rem 0;
  }
  .collection-item {
    width: 60%;
    margin: 2rem auto 0;
    font-size: 1rem;
    display: flex;
    justify-content: space-around;
    color: #2c2e50;
    padding: 2rem 0;
    box-sizing: border-box;
    box-shadow: .3rem .3rem .5rem #bbbbbb;
  }
  .item-img {
    width: 25%;
    border: 1px solid #3a3a3a;
  }
  .item-content {
    width: 65%;
    padding: 2rem 0;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
  }
  .item-content-title {
    font-size: 1.5rem;
    font-weight: bold;
  }
  .item-content-position {
    margin-top: 1rem;
  }
  .item-content-left {
    width: 80%;
  }
  .item-content-right {
    width: 10%;
    margin-right: 5%;
    display: flex;
    align-items: center;
  }
  .item-content-right-btn {
    height: 2rem;
    padding: 1rem;
    border-radius: 1rem;
    border: .1rem solid #3a3a3a;
    text-align: center;
  }
</style>
